package com.sias.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sias.common.result.Result;
import com.sias.common.result.ResultCodeEnum;
import com.sias.entity.dto.UserDetailsDto;
import com.sias.entity.dto.UserDto;
import com.sias.entity.vo.UserDetailsVo;
import com.sias.entity.vo.UserVo;
import com.sias.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "/user")
public class UserController {
//111
    @Autowired
    private UserService userService;

    @Operation(description = "展示所有用户")
    @GetMapping(value = "/listAll/{pageNum}/{pageSize}")
    public Result<Page<UserVo>> listAll(UserDto userDto,
                                        @PathVariable(value = "pageNum") Integer pageNum,
                                        @PathVariable(value = "pageSize") Integer pageSize) {

        Page<UserVo> pageUserVo = userService.listAll(userDto,pageNum,pageSize);
        return Result.build(pageUserVo, ResultCodeEnum.SUCCESS) ;
    }

    @Operation(description = "新增用户")
    @PostMapping(value = "/saveUser")
    public Result saveUser(@RequestBody UserDetailsDto userDetailsDto) {
        userService.saveUserDetails(userDetailsDto);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(description = "删除用户")
    @DeleteMapping(value = "/deleteUser/{userId}")
    public Result deleteUser(@PathVariable String userId) {
        int i= userService.deleteUser(userId);
        return Result.build(i , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(description = "查询用户")
    @PostMapping(value = "/selectUser/{userId}")
    public Result updateUser(@PathVariable String userId) {
        UserDetailsVo userDetailsVo = userService.selectById(userId);
        return Result.build(userDetailsVo , ResultCodeEnum.SUCCESS) ;
    }
    @Operation(description = "修改用户")
    @PostMapping(value = "/updateUser")
    public Result updateUser(@RequestBody UserDetailsDto userDetailsDto) {
        int  i= userService.updateUserDetailsVip(userDetailsDto);
        return Result.build(i , ResultCodeEnum.SUCCESS) ;
    }

}
